package se.lindstrii.springmvc.myapp.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/helloworld")
public class HelloWorldController {

	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView doGet(@RequestHeader(value="User-Agent") String userAgent) {
		System.out.println("doGet! called by: " + userAgent);

		Person person = new Person();
		person.setFirstName("firstName");
		person.setLastName("laastName");
		person.setBirthYear(74);
		
		ModelAndView mav = new ModelAndView("helloworld");
		mav.addObject("person", person);
		return mav;
	}

	@RequestMapping(method = RequestMethod.POST)
	public String doPost(Person person) {
		System.out.println("doPost!");

		System.out.println("fn " + person.getFirstName());
		System.out.println("ln " + person.getLastName());
		System.out.println("by " + person.getBirthYear());

		return "helloworld";
	}
}
